package org.flexlancer.utils
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.utils.Dictionary;
	
	public class CacheUtils
	{
		public static function WriteCache(parmDictionary:Object,parmFileName:String):void{
			try{
				Path.CreateDirectoryIfNotExists(File.documentsDirectory,parmFileName);
				var file:File = File.documentsDirectory.resolvePath(parmFileName);
				var fs:FileStream = new FileStream();
				fs.open(file,FileMode.WRITE);
				fs.writeObject(parmDictionary);
				fs.close();
			}catch(err:Error){
				throw err;
			}
		}
		public static function ReadCache(parmDictionary:Object,parmFileName:String):void{
			try{
				var file:File = File.documentsDirectory.resolvePath(parmFileName);
				if ( file.exists ){
					var fs:FileStream = new FileStream();
					fs.open(file,FileMode.READ);
					var obj:Object = fs.readObject();
					var attr:String;
					for ( attr in obj ){
						parmDictionary[attr] = obj[attr];
					}
					
					fs.close();
				}
			}catch(err:Error){
				throw err;
			}
		}
	}
}